<?php

class MDPasajerosTableDraw
{

public static $instance; 

public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new MDPasajerosTableDraw();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	

function DrawTable($title,$table,$growtable,$campos,$idtour)//obligatorio ID como campo inicial
    {
 
    $qu0="select idTourPax from ". "$table". " where tour_idTour =". "$idtour";
    $table0 = CModelo::getInstance()->getData($qu0);
    
    
    
    $identificadores0="";
    foreach($table0 as $id0=>$valor0){
        $identificadores = $valor0;
        foreach($identificadores as $id1=>$valor1){
            $identificadores0=$identificadores0. "$valor1,";
        }
    }
  $identificadores0= "(". substr($identificadores0,0,strlen($identificadores0)-1). ")";
  
    echo $identificadores0;
    
     $qu="select ";
    $i = 0;
    $i = 0;
    foreach($campos as $id=>$valor)
    {
    $qu=$qu."$id,";
    }
    $qu=substr($qu,0,strlen($qu)-1);


//SELECT idTourPax, pasajero_idPax, NumDocPax, GenPax, FirstNamPax, LastNamPax
//FROM tour_has_pasajero
//CROSS JOIN pasajero ON tour_has_pasajero.pasajero_idPax = pasajero.idPax
//WHERE tour_has_pasajero.idTourPax
//IN ( 301, 601 )
//LIMIT 0 , 30



    $qu=$qu." from $table cross join $growtable ON $table.pasajero_idPax=$growtable.idPax where $table.idTourPax IN $identificadores0";
    
    echo "$qu";
    
    echo "<div id='content_area_user_title'>";
    echo "<h2> $title</h2>";
    echo "</div>";


    echo	"<form>";						
    echo "<form id='filter-form'>Buscar pasajeros: <input name='filter' id='filter' value='' maxlength='30' size='30' type='text'></form><br>";
    echo "</form>";
   
    echo "<div class='usersettings_statistics'>"; 
 


    echo "<table class='food_planner'><thead><tr><th colspan='2'></th><tr></thead>";
    echo "<tbody><tr style='display: table-row;'>";

     //echo "<table> <tbody>";


  
    foreach($campos as $id=>$valor){
  
    echo "<td><h3>$valor</h3></td>";
    
    }
 echo "<tr class='odd'>";
  foreach($campos as $id=>$valor){
  
    echo "<td><input type='text' name='$id' class='general-textarea'></td>";
    
    }
    
    // $qu="select*from $table";
    $table=CModelo::getInstance()->getData($qu);
//var_dump($table);
    $cont=0;
    $ruta=CConfig::getInstance()->rutalocal."/MDOperatorGeneral/MDPasajeros";
    
    
    foreach($table as $campo => $valor)
    { 



$cont=$cont+1;
if($cont%2){




echo "<tr class='odd'>";
$i="";$cont=0;
foreach($valor as $id=>$val)
{ if($cont==0){$i=$val;}

echo "<td width='10%'>$val</td>";$cont=$cont+1;
}
/*---------------------------------------------------------------------------*/
// las referencias debbden de ser modificadas deacuerdo al directorio
//
/*---------------------------------------------------------------------------*/
echo "<td> <a href='$ruta/CPaxEdit.php?codigo=$i&action=1'>Editar</a> </td>";
echo "<td><a href='/modificar.php?codigo=$i'>Eliminar</a> </td>";

echo "</tr>";
}
else
{

echo "<tr class='even'> ";
$i2="";$cont2=0;
foreach($valor as $id => $val)
{ if($cont2==0){$i2=$val;}
echo "<td width='10%'>$val </td>";$cont2=$cont2+1;
}
echo "<td> <a href='$ruta/CPaxEdit.php.php?codigo=$i2&action=1'>Editar</a> </td>";
echo "<td><a href='/modificar.php?codigo=$i2'>Eliminar</a> </td>";
echo "</tr>";
}

}
echo "</td></tr></tbody></table><br><br>";


echo "</div>";

} 



}
?>